/**
 *  		每位工程师都应该保持优雅的代码
 *		Every engineer should keep the elegant code
 */

//var api = "http://dev-static.liqiang365.com"; //演练测试
//var appid = "wx3ba753e6caa82cc8";
//
//var api = "http://dev-static.liqiang365.com"; //测试
//var appid = "wx3ba753e6caa82cc8";

var api = "http://www.liqiang365.com";	    //正式
var appid = "wxf652c39f008f60f1";				

//https_domain = "https://dev-api.liqiang365.com"; //测试
//https_pay_domain = "https://dev-pay.liqiang365.com";

https_domain = "https://api.liqiang365.com"; //线上
https_pay_domain = "https://pay.liqiang365.com";

var BASE = {

}

var slide = https_domain + "/video/get/slide"; //轮播图片
var sfEnlei = https_domain + "/videocourse/list/group"; //查询大类
var selectSFenleiTwo = https_domain + "/videocourse/list/group/two";  //查询中类
var selectSFenleikc = https_domain + "/videocourse/list"; //课程列表
var selectSFenleiByzjid = https_domain + "/videocourse/detail"; //查询课程详情
var selectBykcid = https_domain + "/video/list";//视频列表
var selectSShoucangByRyid = https_domain + "/videocollect/list"; //获取收藏
var addPlaycount = https_domain +"/video/update/playcount"; //增加播放量
var selectByzjid = https_domain + "/video/detail"; //视频详情

var groupbuystat_get = https_domain + "/groupbuystat/get"; //查询我的团购统计信息
var selectSDingdanByRyid = https_domain + "/order/list"; //查询我的订单
var insertSYinhangka = https_domain + "/userbankcard/save";//银行卡添加
var selectSYinhangkaByRyid = https_domain + "/userbankcard/list";//银行卡列表查询

var appSTeamBuyBrokerage = https_domain + "/groupbuybrokerage/list";//查询我的佣金列表
var selectGiftCardByRyid = https_domain + "/groupbuy/gift"; //查询礼品卡列表
var appSTeamBuyGet = https_domain + "/groupbuy/list";// 我的团购列表查询
var appSTeamBuySplitGet = https_domain + "/groupbuysplit/list"; //拆分列表查询
var selectSJiluInfoByzjid = https_domain + "/message/detail"; //根据消息id查询消息详情
var selectSJiluByRyidAll = https_domain + "/message/list";// 查询我的消息 type=1是平台消息
var selectSTixian_list = https_domain + "/moneydraw/list" //提现记录列表查询
var insertSAdvice = https_domain + "/feedback/save"; //意见反馈
var updPassword = https_domain + "/userpwd/update"; //修改密码

var selectMyTuanduiBySeriesH5 = https_domain + "/userteam/list/tree"; //查询我的一级团队 
var selectMyTuanduiBySeriesH5_Two = https_domain + "/userteam/list/tree2"; //查询我的一级团队 
var selectMyTuanduiByPhone = https_domain + "/userteam/list/phone"; //查询我的一级团队 

var selectMyTuanduiAll = https_domain + "/userteam/sum"; //查询团队统计信息
var selectMySShouyi = https_domain + "/moneyincome/list"; //查询我的收益记录
var selectTransferRecordByUid = https_domain + "/message/list/transfer"; //转账列表查询
var slectInfoByUid = https_domain + "/user/get" //查询个人信息
var uploadImage = https_domain + "/upload/image" 
var checkIdentifyingcode = https_domain + "/sms/check"; //验证短信验证码是否正确
var insertSTixian = https_domain + "/moneydraw/save";
var sendCodeCheck = https_domain + "/sms/send";  //发送验证码
var save = https_domain + "/groupbuy/save"; //申请团购

var orderSave = https_domain + "/order/save"; //添加订单

var loginAjax = https_domain + "/login/in.ph" //登录
var register = https_domain + "/register/reg.ph"; //注册

var updatepassword = https_domain + "/userpwd/forget"; //忘记密码
var appSTeamBuySplitSave = https_domain + "/groupbuysplit/save"; //拆分申请

var groupbuychange =  https_domain + "/groupbuychange/save"; //团购转换


var payxuliecode = https_pay_domain + "/codepay/pay";
var getUserOpenid = https_domain + "/weixingz/openid"; //获取openid
var wechatTiXian = https_pay_domain + "/wxredpacket/send"; //红包提现

var weixin_sign = https_pay_domain + "/wxpay/sign"; //微信支付
var yeepay_sign = https_pay_domain + "/yeepay/sign"; //易宝支付

var weixingz_auth = https_domain + "/weixingz/auth";
var weixingz_jsapi = https_domain + "/weixingz/jsapi";

var prize_count = https_domain + "/prize/count"; // 获取抽奖次数
var prize_record = https_domain + "/prize/record"; // 获取中奖名单
var prize_roll = https_domain + "/prize/roll"; // 摇奖


/**
 * 获取URL参数
 */
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if(r != null)
		return unescape(r[2]);
	return null;
}

function getRequest() {
	var url = window.location.search; //获取url中"?"符后的字串   
	var theRequest = new Object();
	if(url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for(var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
		}
	}
	return theRequest;
}

/*
 * ajax封装 
 */

function ajaxPostAsyncData(url, data, async, successfn, complate) {
	data = (data == null || data == "" || typeof(data) == "undefined") ? {
		"date": new Date().getTime()
	} : data;
	data['updateVersion'] = "V2.0";
	data['clientType'] = "1";

	if(getCookie('isLogin') == "2") {
		if(getCookie('cookie_brsy_h5_token') == "null" || !getCookie('cookie_brsy_h5_token')) {
			clearCookie();
		} else {
			data['token'] = getCookie('cookie_brsy_h5_token');

		}
	}

	var ajaxTimeoutTest = $.ajax({
		type: "post",
		data: data,
		timeout: 5000,
		async: async,
		url: url,
		dataType: "json",
		beforeSend: function(XMLHttpRequest) {},
		success: function(d) {

			//if(d.code == "40002") {
			//	return;
			//}
			//successfn(d);
			if(d.code == "40000") {
				successfn(d);
			} else if(d.code == "40003") { //token有误
				var code = getQueryString("code");
				$.jBox.tip("数据有误，请重新登录！!", "error");
				setTimeout(function(){
					window.location.href = "/static/wechat/src/admin/login/upgrade_login.html?code=" + code;
				},2000)
			} else if(d.code == "40008" && getCookie('cookie_brsy_h5_token') == null) { //参数有误 
				var code = getQueryString("code");
				$.jBox.tip("参数有误，请重新登录！!", "error");
				setTimeout(function(){
					window.location.href = "/static/wechat/src/admin/login/upgrade_login.html?code=" + code;
				},2000)
				
				
			} else {
				//				$.jBox.tip("失败!" + d.info, "error");
				successfn(d);
				return;
			}
		},
		complete: function(XMLHttpRequest, textStatus) {
//			if(complate) {
//				complate(XMLHttpRequest, textStatus);
//			};
			
			if(textStatus == 'timeout' || textStatus == 'error') { //超时,status还有success,error等值的情况
				complate(XMLHttpRequest);
			}
		},
		error: function(e) {}
	});
};


/*
 * ajax封装 
 */

function ajaxPostAsyncData_share(url, data, async, successfn, complate) {
	data = (data == null || data == "" || typeof(data) == "undefined") ? {
		"date": new Date().getTime()
	} : data;
	data['updateVersion'] = "V2.0";
	data['clientType'] = "1";

	var ajaxTimeoutTest = $.ajax({
		type: "post",
		data: data,
		timeout: 5000,
		async: async,
		url: url,
		dataType: "json",
		beforeSend: function(XMLHttpRequest) {},
		success: function(d) {
			if(d.code == "40000") {
				successfn(d);
				return;
			} else {
				$.jBox.tip("失败!" + d.info, "error");
				return;
			}
		},
		complete: function(XMLHttpRequest, textStatus) {
//			if(complate) {
//				complate(XMLHttpRequest, textStatus);
//			};
			
			if(textStatus == 'timeout' || textStatus == 'error') { //超时,status还有success,error等值的情况
				complate(XMLHttpRequest);
			}
		},
		error: function(e) {}
	});
};

//webajax封装
function ajaxWebPostAsyncData (url, data, async, successfn, complate) {
	data = (data == null || data == "" || typeof(data) == "undefined") ? {
		"date": new Date().getTime()
	} : data;
	data['updateVersion'] = "V2.0";
	data['clientType'] = "1";
	data["actionName"]=url;
	if(getCookie('isLogin') == "2") {
		if(getCookie('cookie_brsy_pc_token') == null) {
			clearCookie();
		} else {
			data['token'] = getCookie('cookie_brsy_pc_token');

		}
	}
	var ajaxTimeoutTest = $.ajax({
		type: "post",
		data: data,
		timeout: 5000,
		async: async,
		url : "/indexServlet",
		dataType: "json",
		beforeSend: function(XMLHttpRequest) {},
		success: function(d) {
			//if(d.code == "40002") {
			//	return;
			//}
			//successfn(d);
			if(d.code == "40000") {
				successfn(d);
			} else if(d.code == "40003") { //token有误
				var code = getQueryString("code");
				$.jBox.tip("数据有误，请重新登录！!", "error");
				setTimeout(function(){
					window.location.href = "/static/login/shipin/new_login.html";
				},2000)
			} else if(d.code == "40008" && getCookie('cookie_brsy_pc_token') == null) { //参数有误 
				var code = getQueryString("code");
				$.jBox.tip("参数有误，请重新登录！!", "error");
				setTimeout(function(){
					window.location.href = "/static/login/shipin/new_login.html";
				},2000)
				
				
			} else {
				//				$.jBox.tip("失败!" + d.info, "error");
				successfn(d);
				return;
			}
		},
		complete :function  (XMLHttpRequest, textStatus) {
//			if(complate) {
//				complate(XMLHttpRequest, textStatus);
//			};
			
			if(textStatus == 'timeout' || textStatus == 'error') { //超时,status还有success,error等值的情况
				complate(XMLHttpRequest);
			}
		},
		error: function(e) {}
	});
}

/**
 * Cookie 操作
 */
function getCookie(name) {
	var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
	if(arr = document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return null;
}

function setCookie(name, value) {
	var exp = new Date();
	exp.setTime(exp.getTime() + 3 * 24 * 60 * 60 * 1000); //3天过期  
	document.cookie = name + "=" + encodeURIComponent(value) + ";expires=" + exp.toGMTString() + ";path=/";
	return true;

}
//清理cookie
function clearCookie() {

	var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
	if(keys) {
		for(var i = keys.length; i--;)
			document.cookie = keys[i] + "=;expires=" + (new Date(0)).toUTCString() + ";path=/";
	}
	var code = getQueryString("code");
	window.location.href = "/static/wechat/src/admin/login/upgrade_login.html?code=" + code;
}

function clearCookie_new() {

	var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
	if(keys) {
		for(var i = keys.length; i--;)
			document.cookie = keys[i] + "=;expires=" + (new Date(0)).toUTCString() + ";path=/";
	}
}

/**
 * Scroll刷新
 */
function loaded() {
	//定义一系列变量
	if(!page == "1") {
		var myScroll;
	}

	var upIcon = $("#up-icon");
	var downIcon = $("#down-icon");
	//new一个iscroll对象
	myScroll = new IScroll('#wrapper', {
		probeType: 3,
		click: true,
		mouseWheel: true,
		preventDefaultException: {
			tagName: /^(INPUT|P)$/
		}

	});

	myScroll.on("scroll", function() {
		var y = this.y; //拉的距离（负数）
		//console.log(y)
		var maxY = this.maxScrollY - y; //整个页面高度-拉的距离=整个页面高度
		//console.log(maxY)
		var downHasClass = downIcon.hasClass("reverse_icon");
		var upHasClass = upIcon.hasClass("reverse_icon");
		if(y >= 40) {
			!downHasClass && downIcon.addClass("reverse_icon");
			return "";
		} else if(y < 40 && y > 0) {
			downHasClass && downIcon.removeClass("reverse_icon");
			return "";
		}

		if(maxY >= 40) {
			!upHasClass && upIcon.addClass("reverse_icon");
			return "";
		} else if(maxY < 40 && maxY >= 0) {
			upHasClass && upIcon.removeClass("reverse_icon");
			return "";
		}
	});

	//自定义上拉刷新
	myScroll.on("slideUp", function() {

		if(this.maxScrollY - this.y > 40) {
			console.log('调用')
			getdataafter();
			upIcon.removeClass("reverse_icon");
			setTimeout(function() {
				myScroll.refresh()
			}, 300)

		}
	});
}


function hhhh(){
	
	
	
	
}
